//
// Created by kevin on 2024/12/2.
//


#include "tx_PRBSGeneration_lte.h"
#include "utils.h"

u8* tx_PRBSGeneration_lte(int initC, int sequenceLength){
    int nC =  1600;

    int buf_len = nC + sequenceLength;
    u8 *x1 = new u8 [buf_len+32];
    memset(x1, 0x00, sizeof(u8)*buf_len);
    x1[0] = 1;

    int nLengthInitCBinary = getbitnums(initC);
    u8* x2 = new u8 [buf_len+32];
    memset(x2,0x00,sizeof(u8)*buf_len);
    for(int i = 0; i < nLengthInitCBinary; i++){
        x2[i] = (initC >> i) & 0x1;
    }

    for(int i = 0; i < buf_len; i++){
        x1[i+31] = (x1[i+3] + x1[i]) % 2;
        x2[i+31] = (x2[i+3] + x2[i+2] + x2[i+1] + x2[i] )% 2;
    }

    u8 *sequencePRBS = new u8[sequenceLength];
    for(int i = 0; i < sequenceLength; i++){
        sequencePRBS[i] = (x1[i + nC] + x2[i+nC]) % 2;
    }

    return sequencePRBS;
}